﻿//-----------------------------------------------------------------------------
// <copyright file="SaveFileDialogImplementer.cs" company="William E. Kempf">
//     Copyright (c) William E. Kempf.
// </copyright>
//-----------------------------------------------------------------------------

namespace Onyx.Windows
{
    using System.IO;
    using System.Windows;
    using Microsoft.Win32;

    /// <summary>
    /// Provides a standard implementation of <see cref="ISaveFileDialog"/> that
    /// defers operations to a <see cref="Microsoft.Win32.SaveFileDialog"/>.
    /// </summary>
    public class SaveFileDialogImplementer : FileDialogImplementer<SaveFileDialog>, ISaveFileDialog
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SaveFileDialogImplementer"/>
        /// class.
        /// </summary>
        /// <param name="owner">The owner <see cref="Window"/>.</param>
        public SaveFileDialogImplementer(Window owner)
            : base(owner, new SaveFileDialog())
        {
        }

        /// <summary>
        /// Gets or sets a value indicating whether <see cref="ISaveFileDialog"/>
        /// prompts the user for permission to create a file if the user specifies
        /// a file that does not exist.
        /// </summary>
        /// <value><see langword="true"/> if dialog should prompt prior to saving to a filename
        /// that does not previously exist; otherwise, <see langword="false"/>. The default is
        /// <see langword="false"/>.</value>
        public bool CreatePrompt
        {
            get
            {
                return Dialog.CreatePrompt;
            }

            set
            {
                Dialog.CreatePrompt = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether <see cref="ISaveFileDialog"/>
        /// displays a warning if the user specifies the name of a file that already
        /// exists.
        /// </summary>
        /// <value><see langword="true"/> if dialog should prompt prior to saving over a filename that previously existed;
        /// otherwise <see langword="false"/>. The default is <see langword="true"/>.</value>
        public bool OverwritePrompt
        {
            get
            {
                return Dialog.OverwritePrompt;
            }

            set
            {
                Dialog.OverwritePrompt = value;
            }
        }

        /// <summary>
        /// Creates a read-write file stream for the filename selected by the user
        /// using <see cref="ISaveFileDialog"/>.
        /// </summary>
        /// <returns>A new <see cref="System.IO.Stream"/> that contains the selected
        /// file.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// No files were selected in the dialog.
        /// </exception>
        /// <remarks>The file stream that is returned is opened with read-write access
        /// (<see cref="System.IO.FileMode.Create"/> and
        /// <see cref="System.IO.FileMode"/>).</remarks>
        public Stream OpenFile()
        {
            return Dialog.OpenFile();
        }
    }
}
